
/**
 * Protocol is under GNU/GPL2!
 * Author: Benedikt Sauter sauter@empronix.com, 2007-09-02
 * 
 * BYTE       command
 * BYTE       parameter
 * BYTE       length body <x>
 * <x> BYTES  body
 *
 * max body length = 60 bytes
 */

#ifndef _PROTOCOL_H_
#define _PROTOCOL_H_

/**
 * The first byte in the body of an response packet 
 * is always a value from the next table.
 */

//////////////////////////////////////////////////////////////////////////////

#define RSP_OK                          0x01
#define RSP_ERROR                       0x02
#define RSP_UNKOWN_CMD                  0x03
#define RSP_UNKOWN_PIN                  0x04
#define RSP_WRONG_PIN_CONFIG            0x05
#define RSP_IMPOSSIBLE_PIN_CONFIG       0x05
#define RSP_TIMEOUT                     0x06

//////////////////////////////////////////////////////////////////////////////

#define CMD_LATENCY_TIMER_SET           0x01
#define CMD_LATENCY_TIMER_GET           0x02
#define CMD_GET_HW_ID                   0x03

//////////////////////////////////////////////////////////////////////////////

#define CMD_IO_INIT_PORT                0x10
#define CMD_IO_INIT_PIN                 0x11
#define CMD_IO_PORT_DIRECTION_IN        0x12
#define CMD_IO_PORT_DIRECTION_OUT       0x13
#define CMD_IO_PORT_DIRECTION_TRI       0x14
#define CMD_IO_PIN_DIRECTION_IN         0x15
#define CMD_IO_PIN_DIRECTION_OUT        0x16
#define CMD_IO_PIN_DIRECTION_TRI        0x17
#define CMD_IO_PORT_SET                 0x18
#define CMD_IO_PORT_GET                 0x19
#define CMD_IO_PIN_SET                  0x1A
#define CMD_IO_PIN_GET                  0x1B

//////////////////////////////////////////////////////////////////////////////

#define CMD_ADC_INIT_PIN                0x20
#define CMD_ADC_GET                     0x21
#define CMD_ADC_REF                     0x22

//////////////////////////////////////////////////////////////////////////////

#define CMD_I2C_INIT                    0x30
#define CMD_I2C_DEINIT                  0x31
#define CMD_I2C_BITRATE                 0x32
#define CMD_I2C_SEND_BYTES              0x34
#define CMD_I2C_RECV_BYTES              0x35
#define CMD_I2C_SEND_START              0x36
#define CMD_I2C_SEND_STOP               0x37

//////////////////////////////////////////////////////////////////////////////

#define CMD_SPI_INIT		  0x40
#define CMD_SPI_DEINIT		  0x41
#define CMD_SPI_SPEED		  0x42
#define CMD_SPI_SEND		  0x43
#define CMD_SPI_RECV		  0x44
#define CMD_SPI_SEND_AND_RECV	  0x45

//////////////////////////////////////////////////////////////////////////////
// ramcard commands

#define CMD_RC_INIT                     0xF0	// no need so far
#define CMD_RC_PAGE_GET                 0xF1	// page number
#define CMD_RC_PAGE_PUT                 0xF2	// page number, x bytes
#define CMD_RC_HAVE_CARD                0xF3

//////////////////////////////////////////////////////////////////////////////

#define RC_PAGE_SIZE                    256	// page size is not flexible in device

//////////////////////////////////////////////////////////////////////////////

#define PARAM_ADC_AREF                  0x01
#define PARAM_ADC_AVCC                  0x02
#define PARAM_ADC_INTERNAL              0x03

#endif /* _PROTOCOL_H_ */
